package com.heima.gateway.properties;


import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;


import java.util.Arrays;
import java.util.List;

@Data
@Component
@ConfigurationProperties(prefix = "app-gateway")
public class AllowedUrlsProperties {

    private String allowedUrls;

    // 可以添加一个方法来检查URL是否被允许
    public boolean isUrlAllowed(String url) {
        if (allowedUrls == null){
            return true;
        }
        // 使用split方法按逗号分割字符串，结果是一个字符串数组
        String[] urls = allowedUrls.split(",");
        // 使用Arrays.asList将数组转换为List
        List<String> urlList = Arrays.asList(urls);
        System.out.println(urlList);
        for (String u : urlList) {
            if (u.equals(url)) {
                return true;
            }
        }
        return false;
    }
}